//
//  MKUIThemePickerBase.m
//  MKUI
//
//  Created by 苏尚进 on 2021/3/20.
//  Copyright © 2021 moon. All rights reserved.
//

#import "MKUIThemePickerBase.h"

@implementation MKUIThemePickerBase
- (instancetype)initWithObjSelector:(SEL)objSelector{
    if (self=[self init]) {
        self.objSelector = objSelector;
    }
    return self;
}
- (NSString *)pickerKey{
    return NSStringFromSelector(self.objSelector);
}
- (void)applyThemeTo:(NSObject *)object{
}
#ifdef DEBUG
- (void)dealloc{
    
}
#endif
@end

#import "UIColor+MKUITheme.h"
@implementation MKUIThemePickerBase (Element)
+ (nullable UIColor *)themeUIColorWithElement:(id<MKUIThemeElementProtocol>)element{
    UIColor *value = nil;
    id themeElement = element.themeElement;
    if([themeElement isKindOfClass:[UIColor class]]){
        value = (UIColor *)themeElement;
    }else if([themeElement isKindOfClass:[NSString class]]){
        value = [UIColor mktheme_colorWithString:(NSString *)themeElement];
    }
    return value;
}
+ (nullable UIImage *)themeUIImageWithElement:(id<MKUIThemeElementProtocol>)element{
    id themeValue = element.themeElement;
    UIImage *value = nil;
    if([themeValue isKindOfClass:[UIImage class]]){
        value = (UIImage *)themeValue;
    }else if([themeValue isKindOfClass:[NSString class]]){
        value = [UIImage imageNamed:(NSString *)themeValue];
    }
    return value;
}
+ (CGColorRef)themeCGColorRefWithElement:(id<MKUIThemeElementProtocol>)element{
    CGColorRef value = NULL;
    id themeElement = element.themeElement;
    if([themeElement isKindOfClass:[UIColor class]]){
        value = [(UIColor *)themeElement CGColor];
    }else if([themeElement isKindOfClass:[NSString class]]){
        value = [UIColor mktheme_colorWithString:(NSString *)themeElement].CGColor;
    }else{
        value = (__bridge CGColorRef)(themeElement);
    }
    return value;
}
+ (NSInteger)themeNSIntegerWithElement:(id<MKUIThemeElementProtocol>)element{
    id themeValue = element.themeElement;
    NSInteger value = 0;
    if([themeValue isKindOfClass:[NSNumber class]]){
        value = [(NSNumber *)themeValue integerValue];
    }else if([themeValue isKindOfClass:[NSString class]]){
        value = [(NSString *)themeValue integerValue];
    }
    return value;
}
+ (CGFloat)themeCGFloatWithElement:(id<MKUIThemeElementProtocol>)element{
    id themeValue = element.themeElement;
    CGFloat value = 0;
    if([themeValue isKindOfClass:[NSNumber class]]){
        value = [(NSNumber *)themeValue floatValue];
    }else if([themeValue isKindOfClass:[NSString class]]){
        value = [(NSString *)themeValue floatValue];
    }
    return value;
}
+ (CGSize)themeCGSizeWithElement:(id<MKUIThemeElementProtocol>)element{
    id themeValue = element.themeElement;
    CGSize value = CGSizeZero;
    if([themeValue isKindOfClass:[NSValue class]]){
        value = [(NSValue *)themeValue CGSizeValue];
    }
    return value;
}
@end
